var mongoose = require('mongoose');
mongoose.Promise = global.Promise;
var dbURI = 'mongodb://127.0.0.1:10001,127.0.0.1:10003,127.0.0.1:10005/picApp?replicaSet=shard0&readPreference=secondary';
if(process.env.RUN_ENV === 'ONLINE' && process.env.IS_TEST !== 'Y'){
    dbURI = `mongodb://root:TPxu234!#@dds-2ze262ac5bbf14841.mongodb.rds.aliyuncs.com:3717,dds-2ze262ac5bbf14842.mongodb.rds.aliyuncs.com:3717/picApp?replicaSet=mgset-15036439&readPreference=secondary&authSource=admin`;
}

const options = {
    useMongoClient: true,
    autoReconnect: true
}

mongoose.connect(dbURI, options).then(() => {
    console.log('Mongoose connection open to ' + dbURI);
})
.catch((err) => {
    console.log(err)
})


module.exports = mongoose;